<template>
  <div>
    <el-card shadow="never" class="mb20">
      <div class="filter-container">
        <div class="filter-item">
          <label class="radio-label">表单名称：</label>
          <el-input v-model="listQuery.tableComment" placeholder="表单名称" style="width: 200px;" @keyup.enter.native="handleFilter" />
        </div>
        <el-button class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter" >
          查询
        </el-button>
        <el-button class="filter-item" icon="el-icon-refresh-left" @click="handleReset">
          重置
        </el-button>
      </div>
    </el-card>
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      row-key="tableId"
      border
      stripe
      fit
      highlight-current-row
      :tree-props="{children: 'childList'}"
      @row-click="handleRow">
      <el-table-column prop="tableName" label="表名" min-width="150" header-align="center" align="left"></el-table-column>
      <el-table-column prop="tableComment" label="表单名称" min-width="200" align="center">
      </el-table-column>
      <el-table-column prop="tableDef" label="表定义" width="80" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.tableDef | tableDefFilter }}</span>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="listQuery.pageNo" :limit.sync="listQuery.pageSize" @pagination="fetchData" />
  </div>
</template>

<script>
import { getPageList } from '@/api/workflow/form/table'
import Pagination from '@/views/workflow/components/Pagination'
import enums from '@/views/workflow/utils/enum'
export default {
  components: { Pagination },
  filters: {
    tableDefFilter(type) {
      return enums.TAB_DEF[type]
    }
  },
  data() {
    return {
      total: 0,
      listQuery: {
        tableComment: '',
        pageNo: 1,
        pageSize: 10
      },
      list: [],
      listLoading: true
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    handleFilter() {
      this.listQuery.pageNo = 1
      this.fetchData()
    },
    handleReset() {
      this.listQuery.tableComment = ''
      this.handleFilter()
    },
    fetchData() {
      this.listLoading = true
      getPageList(this.listQuery).then(response => {
        this.total = response.data.total
        this.list = response.data.rows
        this.listLoading = false
      })
    },
    handleRow(row) {
      this.$emit('callbackFormTable', row)
    }
  }
}
</script>
